package com.code.vo;

import java.util.Map;

public class JSONVO {
	
	private Object data;
	private boolean success = true;
	private int curPage = 0;
	private int pageRow = 0;
	private int totalPage = 0;
	private int totalRow = 0;
	
	public JSONVO() {
	}
	
	public JSONVO(Object data) {
		this.data = data;
	}
	
	public JSONVO(Object data, PageVO pageVO) {
		this.data = data;
		this.curPage = pageVO.getCurPage();
		this.pageRow = pageVO.getPageRow();
		this.totalPage = pageVO.getTotalPage();
		this.totalRow = pageVO.getTotalRow();
	}
	
	public JSONVO(Object data, Map<String, Object> map) {
		PageVO pageVO = new PageVO();
		pageVO.setCurPage((Integer) map.get("curPage"));
		pageVO.setPageRow((Integer) map.get("pageRow"));
		pageVO.setTotalRow((Integer) map.get("totalRow"));
		
		this.data = data;
		this.curPage = pageVO.getCurPage();
		this.pageRow = pageVO.getPageRow();
		this.totalPage = pageVO.getTotalPage();
		this.totalRow = pageVO.getTotalRow();
	}
	
	public JSONVO(Object data, PageVO pageVO, boolean success) {
		this.data = data;
		this.curPage = pageVO.getCurPage();
		this.pageRow = pageVO.getPageRow();
		this.totalPage = pageVO.getTotalPage();
		this.totalRow = pageVO.getTotalRow();
		this.success = success;
	}
	
	public Object getData() {
		return data;
	}
	public void setData(Object data) {
		this.data = data;
	}
	public boolean isSuccess() {
		return success;
	}
	public void setSuccess(boolean success) {
		this.success = success;
	}
	public int getCurPage() {
		return curPage;
	}
	public void setCurPage(int curPage) {
		this.curPage = curPage;
	}
	public int getTotalPage() {
		return totalPage;
		
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public int getPageRow() {
		return pageRow;
	}
	public void setPageRow(int pageRow) {
		this.pageRow = pageRow;
	}
	public int getTotalRow() {
		return totalRow;
	}
	public void setTotalRow(int totalRow) {
		this.totalRow = totalRow;
	}

	@Override
	public String toString() {
		return toJson();
	}
	
	public String toJson() {
		StringBuffer buffer = new StringBuffer();
		
		buffer.append("{");
		buffer.append("success: " + success);
		buffer.append(", data: " + data);
		buffer.append(", curPage: " + curPage);
		buffer.append(", pageRow: " + pageRow);
		buffer.append(", totalPage: " + totalPage);
		buffer.append(", totalRow: " + totalRow);
		buffer.append("}");
		
		return buffer.toString();
	}
}
